package org.apache.servicecomb.samples.practise.houserush.gateway.dispatcher.config;


import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class LoginUrlConfig {
    private DynamicStringProperty needLoginUrls = DynamicPropertyFactory.getInstance().
            getStringProperty("gateway.needLoginUrls","");

    private DynamicStringProperty noNeedLoginUrls = DynamicPropertyFactory.getInstance().
            getStringProperty("gateway.noNeedLoginUrls","");

    private Set<String> needLoginUrlsSet = new HashSet<>(Arrays.asList(needLoginUrls.get().split(",")));
    private Set<String> noNeedLoginUrlsSet = new HashSet<>(Arrays.asList(noNeedLoginUrls.get().split(",")));

    public LoginUrlConfig() {
        needLoginUrls.addCallback(() -> needLoginUrlsSet = new HashSet<>(Arrays.
                asList(needLoginUrls.get().split(","))));

        noNeedLoginUrls.addCallback(() -> noNeedLoginUrlsSet = new HashSet<>(Arrays.
                asList(noNeedLoginUrls.get().split(","))));
    }
    public Set<String> getNeedLoginUrlsSet() {
        return needLoginUrlsSet;
    }

    public Set<String> getNoNeedLoginUrlsSet() {
        return noNeedLoginUrlsSet;
    }
}
